package cn.tedu.cgb2110boot02.axios;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/test/servlet01")
public class ServletDemo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //放行js的请求
        response.setHeader("Access-Control-Allow-Origin","*");
        //解析请求参数
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        System.out.println("11111");
        //给浏览器做出响应
        response.setContentType("text/html;charset=utf8");
        PrintWriter out = response.getWriter();
//        out.write(name+age);
        String json = "{\"name\":\""+name+"\",\"age\":\""+age+"\"}";
        out.write(json);
    }
}
